export class Collition {
    constructor(game,x, y) {
        this.game=game;
        this.spriteWidth = 100;
        this.spriteHeight = 90;
        this.sizeModifiier=Math.random()+0.5
        this.width = this.spriteWidth * this.sizeModifiier;
        this.height = this.spriteHeight * this.sizeModifiier;
        this.x = x-this.width*0.5;
        this.y = y-this.height*0.5;
        this.img = document.getElementById('boom')
        this.frameX = 0;
        this.maxFrame=4;
        this.fps=Math.random()*10+15;
        this.timer = 0;
        this.interval=1000/this.fps;
        this.audio = new Audio();
        this.audio.src = "./src/audio/boom.wav"
        this.deleteFlag=false;

    }
    update(deltaTime) {
        //爆炸音效
        // if (this.frameX==0&&this.timer == 0)
        //     this.audio.play();
        if (this.timer >this.interval) {
            this.frameX++;
            this.timer=0;
            if(this.frameX>this.maxFrame){
                this.deleteFlag=true;
            }
        }else{
            this.timer+=deltaTime;
        }
    }
    draw(ctx) {
        ctx.drawImage(this.img, this.spriteWidth * this.frameX, 0, this.spriteWidth, this.spriteHeight, this.x,this.y, this.width, this.height)
    }
}


